<?php include_once('_head.php');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP 4rum poster</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
</head>
<body>

	<form action="" method="post">
		<table>
			<tr>
				<td>title</td>
				<td><input type="text" id="ptitle" name="title" size="80" value="<?php echo $_POST['title'];?>"/></td>
			</tr>
			<tr id = "correct_wp">
				<td>content</td>
				<td><textarea id="pcontent" rows="20" cols="60" name="content"><?php echo $_POST['content'];?></textarea>Use link?<input type="checkbox" name="Use Links" id="islinks"/></td>
				<td><input type="button" id="correct" value="Correct text"/><input type="button" id="incorrect" value="Back"/></td>
			</tr>
			<tr>
				<td>name of config file</td>
				<td><input type="text" name="file_name" id="file_name" size="80" value="<?php echo $_POST['file_name'];?>" /></td>
				<td><input type="button" name="load_file" id="load_file" value="load me"/></td>	
				<td><input type="button" name="post_data" id="post_data" value="post data"/></td>	
			</tr>
			<tr id="correct_code">
				<td>Input your code</td>
				<td><textarea id="code_content" rows="20" cols="60" name="code_content"></textarea></td>
				<td><input type="button" id="code_correct" value="Correct text"/><input type="button" id="code_incorrect" value="Back"/></td>
			</tr>
		</table>
	<div id="loadimage"><center><img src="load.gif" title="Submitting datas" alt="Please wait.."></center></div>


		<input type="button" id="showtr" value="show field for link tag"/>
		<input type="submit" name="form_submit"/>
	</form>
<script>
	WP_POST = true;
	FR_POST = true;
	$('#loadimage').hide();
	!FR_POST ? $('#correct_code').hide() : 1;
	!WP_POST ? $('#correct_wp').hide() : 1;
	checkMyName = function(filename){
		if( filename.match( /^[\w- ]+\..*$/ ) )
			return 1;
		return 0;
	}
    $(document).ready(function(  ){
		
		$('#showtr').bind('click', function() {
			$('#correct_code').show();
		});
		
		
		$('#code_correct').bind('click', function() {
			mycode = $('#code_content').val();
			var str = $('#code_content').val();
			$.post("catcher.php", {data: str,title:$('#ptitle').val()},
			function(data){
				if(data.length > 0){
					$('#code_content').val(data);
				}else{
					alert('du lieu sai');
				}
			}); 
			
			
		});
		
		$('#code_incorrect').bind('click', function() {
			$('#code_content').val(mycode);
		});
		
		$('#correct').bind('click', function() {
			mytext = $('#pcontent').val();
			var str = $('#pcontent').val();
			// str = str.replace(/<\/blockquote>/g, "[\/code]");
			// str = str.replace(/<blockquote>/g, "[code]");
			str = str.replace(/<a href=\"/g, "[url=");
			str = str.replace(/\"\s?\/><\/a>/g, "[/img][/url]");
			str = str.replace(/\"\s?target=\"_blank\">/g, "]");
			str = str.replace(/<img\s?src=\"/g, "[img]");
			
			
			str = str.replace(/<\/blockquote>/g, "[\/links]");
			str = str.replace(/<blockquote>/g, "[links]");
			str = str.replace(/<strong>/g, "[b]");
			str = str.replace(/<\/strong>/g, "[\/b]");
			if($('#islinks').attr('checked') == true){
				str = str.replace(/\[code\]/g, "[links]");
				str = str.replace(/\[\/code\]/g, "[\/links]");
			}
			$('#pcontent').val(str);
		});
		$('#incorrect').bind('click', function() {
			$('#pcontent').val(mytext);
		});
		

		
		$('#post_data').hide();
		var _fileName = $('#file_name').val() ;
		
		
		(_fileName == "" ? ($('#file_name').val("site.txt")) : 1);
		$('#load_file').bind('click', function() {
			if(checkMyName($('#file_name').val())){
				$('#loadimage').show();
				$.post("_loadfile.php", {filename: $('#file_name').val()},
				function(data){
					$("#loadfile_result").html(data);
					$('#post_data').show();
					$('#loadimage').hide();
				});
			}else{
				alert('Invalid filename');
			}
		});
		$('#post_data').bind('click', function() {
			$('#loadimage').show();
			var mytitle = $('#ptitle').val();
			var mcontent =  $('#pcontent').val();
			mytitle.replace('&', "&amp;");
			mcontent.replace('&', "&amp;");
			if( mytitle.length > 10 || mcontent.length > 30 ){
				$.post("_postHandle.php", {ptitle: mytitle,pcontent:mcontent},
				function(data){
					$('#loadimage').hide();
					$("#post_result").html(data);
				});
			}else{
				alert('30 char');
			}
		});

     });
</script>
<div id="loadfile_result">
</div>
<div id="post_result">
</div>
</body>
</html> 




<?php
//echo ROOTPATH;
echo $_SERVER['DOCUMENT_ROOT'].'/tenfolder/a.txt';
if($_POST['form_submit']){
	print_r($_POST);
}


?>